package com.le.tester.javaThink.fourth.concurrency;

/**
 * createTime：2021/10/22 16:39
 * description：synchronized同步使用
 */

class DualSynch {
    private Object syncObject = new Object();

    public synchronized void f() {
        for (int i = 0; i < 5; i++) {
            System.out.print("f()");
            //线程因为yield()让出了调度，所以没有阻塞
            Thread.yield();
        }
    }

    public void g() {
        synchronized (syncObject) {
            for (int i = 0; i < 5; i++) {
                System.out.print("g()");
                Thread.yield();
            }
        }
    }
}


public class SyncObject {
    public static void main(String[] args) {
        final DualSynch dualSynch = new DualSynch();

        new Thread(dualSynch::f).start();

        dualSynch.g();
    }
}
